package com.uestc.soft.controller;

import com.uestc.soft.pojo.Master;
import com.uestc.soft.service.MasterService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/master")
public class MasterController {

    @Resource
    private MasterService masterService;

    // 所有这些命名按照企业规范，必须一致，但是在java语法本身是没有此约束的
    @RequestMapping("/selectByMaster")
    public Master selectByMaster(@RequestParam Integer master) {
        return masterService.selectByMaster(master);
    }

    @RequestMapping("/selectBMAD")
    public Master selectByMasterAndDivide(@RequestParam Integer master,
                                       @RequestParam String divide) {
        return masterService.selectByMasterAndDivide(master, divide);
    }

    @RequestMapping("/selectByMasters")
    public Map<String, Object> selectByMasters(@RequestBody Master master) {
        Master response_master = masterService.selectByMasters(master);
        Map<String, Object> map = new HashMap<>();   // 初始化一个返回数据对象
        map.put("code", 200);
        map.put("host", response_master);                 //
        return map;
    }

    @RequestMapping("/selectByPage")
    public Map<String, Object> selectByPage(@RequestParam int page,
                                            @RequestParam int limit,
                                            Integer master,
                                            String divide) {
        return masterService.selectByPage(page, limit, master, divide);
    }

    @RequestMapping("/insert")
    public Map<String, Object> insert(@RequestBody Master master) {
        return masterService.insert(master);
    }

    @RequestMapping("/deleteByMaster")
    public Map<String, Object> deleteByMaster(@RequestParam Integer master) {
        return masterService.deleteByMaster(master);
    }

    @RequestMapping("/update")
    public Map<String, Object> update(@RequestParam Integer master, String divide, Integer weakpassword, String LastLoginTime) {
        return masterService.update(master, divide , weakpassword, LastLoginTime);
    }
}